from django.shortcuts import render
from django.http import JsonResponse


def chart_list(request):
    """数据统计列表"""
    return render(request, 'chart_list.html')


def chart_bar(request):
    """构造柱状图"""
    # 数据可以从数据库中获取
    legend = ['大白', '小黑']
    series_list = [
        {
            "name": '大白',
            "type": 'bar',
            "data": [5, 20, 36, 10, 10, 20]
        },
        {
            "name": '小黑',
            "type": 'bar',
            "data": [3, 10, 16, 20, 15, 90]
        }
    ]
    x_axis = ['1月', '2月', '3月', '4月', '5月', '6月']

    result = {
        "status": True,
        "data": {
            "legend": legend,
            "series_list": series_list,
            "x_axis": x_axis,
        }
    }
    return JsonResponse(result)


def chart_pie(request):
    """构造饼状图"""
    db_data_list = [
        {"value": 1048, "name": '技术部'},
        {"value": 735, "name": '运营部'},
        {"value": 580, "name": '新媒体'},
    ]

    result = {
        "status": True,
        "data": db_data_list,
    }
    return JsonResponse(result)


def chart_line(request):
    """构造折线图1"""
    legend = ['上海', '北京']
    x_axis = ['1月', '2月', '3月', '4月', '5月', '6月', '7月']
    series_list = [
        {
            "name": '上海',
            "type": 'line',
            "stack": 'Total',
            "data": [120, 132, 101, 134, 90, 230, 210]
        },
        {
            "name": '北京',
            "type": 'line',
            "stack": 'Total',
            "data": [220, 182, 191, 234, 290, 330, 310]
        },
    ]
    result = {
        "status": True,
        "legend":legend,
        "x_axis": x_axis,
        "series_list": series_list,
    }
    return JsonResponse(result)

def highcharts(request):
    """highcharts示例"""
    return render(request,'highcharts.html')
